package 接口.练习;
//拷贝
class Animal{
    int high;

    public Animal(int high) {
        this.high = high;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Animal{" +
                "high=" + high +
                '}';
    }
}
class Dog implements Cloneable{
    int age ;
    Animal animal;

    public Dog(int age, Animal animal) {
        this.age = age;
        this.animal = animal;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Dog{" +
                "age=" + age +
                ", animal=" + animal +
                '}';
    }
}
public class Clone_Text_1 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Animal animal = new Animal(180);
        Dog dog1 = new Dog(15,animal);
        Dog dog2 =(Dog)dog1.clone();
        System.out.println("拷贝后");
        System.out.println(dog1);
        System.out.println(dog2);
        System.out.println("修改");
        dog2.animal.high = 190;
        System.out.println(dog1);
        System.out.println(dog2);
    }
}
